package plugins.lxfa.mainMenuTop
{
    import caurina.transitions.*;
    
    import core.manager.MainSystemProperty;
    import core.manager.MainSystemPropertyEvent;
    import core.manager.playerManager.musicPlayerManager.*;
    
    import flash.events.*;
    
    import memory.*;
    
    import mx.core.*;
    import mx.managers.BrowserManager;
    
    import util.menu.popumenu.view.*;
    
    import view.fl2mx.*;

    public class MainMenuTop extends UIComponent
    {
        private var head:MainMenuHead;
        private var popupMenuManager:PopupMenuManager;
        private var hasBackGround:Boolean = true;
        private var top:MainMenuTopSwc;
        private var engChina:EngChina;

        public function MainMenuTop()
        {
            head = new MainMenuHead();
            top = new MainMenuTopSwc();
            this.addChild(top);
            top.alpha = 0;
            Tweener.addTween(top, {alpha:1, time:3});
            initLaba();
            initEngChina();
            init();
            return;
        }// end function
        private function initEngChina():void
        {
        	engChina = new EngChina();
            engChina.x = 812;
            engChina.y = 63;
            this.addChild(engChina);
            engChina.china.addEventListener(MouseEvent.CLICK,function():void{
            	BrowserManager.getInstance().setTitle("2010年上海世博会广西体验型展馆");
            	MainSystemProperty.LANGUAGE=MainSystemProperty.CHINESE;
            	MainSystemProperty.getInstance().dispatchEvent(new MainSystemPropertyEvent(MainSystemPropertyEvent.CHANGE_LANGUAGE));
            });
            engChina.eng.addEventListener(MouseEvent.CLICK,function():void{
            	BrowserManager.getInstance().setTitle("Guangxi Experiencing Pavilion in Expo 2010 Shanghai China");
            	MainSystemProperty.LANGUAGE=MainSystemProperty.ENGLISH;
            	MainSystemProperty.getInstance().dispatchEvent(new MainSystemPropertyEvent(MainSystemPropertyEvent.CHANGE_LANGUAGE));
            });
        }
        private function initLaba() : void
        {
            top.laba.buttonMode = true;
            top.laba.stop();
            top.laba.addEventListener(MouseEvent.CLICK, on_laba_click);
            return;
        }// end function

        private function init() : void
        {
            popupMenuManager = new PopupMenuManager();
            popupMenuManager.init(top.lvsejiayuan, top.lvsejiayuan.name, 0);
            popupMenuManager.init(top.lansemengxiang, top.lansemengxiang.name, 1);
            popupMenuManager.init(top.meiguantianxia, top.meiguantianxia.name, 2);
            popupMenuManager.init(top.jinxiuhuazhang, top.jinxiuhuazhang.name, 3);
            popupMenuManager.init(top.shengshihexie, top.shengshihexie.name, 4);
            popupMenuManager.init(top.zonghengsihai, top.zonghengsihai.name, 5);
            popupMenuManager.init(top.yangmengbagui, top.yangmengbagui.name, 6);
            top.stop();
            top.gotoAndStop(top.totalFrames);
            Application.application.addChild(Fl2Mx.fl2Mx(head));
            head.x = 94;
            head.y = 4;
            head.buttonMode = true;
            head.addEventListener(MouseEvent.CLICK, function (_embed_css_Assets_swf_mx_skins_BoxDividerSkin_2014112978:MouseEvent) : void
            {
                var e:* = _embed_css_Assets_swf_mx_skins_BoxDividerSkin_2014112978;
                if (top.currentFrame == 1 || top.currentFrame == 2)
                {
                    top.play();
                    top.addFrameScript(top.totalFrames-1, function () : void
                {
                    top.stop();
                    return;
                }// end function
                );
                }
                if (top.currentFrame == top.totalFrames)
                {
                    top.addEventListener(Event.ENTER_FRAME, enter);
                    top.addFrameScript(1, function () : void
                {
                    top.stop();
                    MemoryRecovery.getInstance().gcFun(top, Event.ENTER_FRAME, enter);
                    return;
                }// end function
                );
                }
                return;
            }// end function
            );
            return;
        }// end function

        private function enter(_embed_css_Assets_swf_mx_skins_BoxDividerSkin_2014112978:Event) : void
        {
            top.prevFrame();
            return;
        }// end function

        private function on_laba_click(_embed_css_Assets_swf_mx_skins_BoxDividerSkin_2014112978:MouseEvent) : void
        {
            if (hasBackGround)
            {
                top.laba.gotoAndStop(2);
                hasBackGround = false;
                BackGroundMusicManager.getInstance().hasBackGroundMusic = false;
            }
            else
            {
                top.laba.gotoAndStop(1);
                hasBackGround = true;
                BackGroundMusicManager.getInstance().hasBackGroundMusic = true;
            }
            return;
        }// end function

        public function dispose() : void
        {
            top.parent.removeChild(top);
            top = null;
            return;
        }// end function

    }
}
